package com.shijiu.controller;

import com.shijiu.annotation.RepeatSubmit;
import com.shijiu.pojo.Shop;
import com.shijiu.service.ShopService;
import com.shijiu.utils.UserThreadLocal;
import com.shijiu.common.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
/**
 * @Author xlj
 * @Date Created in  2023/3/18 14:30
 * @DESCRIPTION:
 * @Version V1.0
 */
@RestController
@RequestMapping("shop")
@Transactional(rollbackFor = Exception.class)
public class ShopController {

    @Autowired
    private ShopService shopService;

    @ApiOperation("根据店铺id 获取信息")
    @GetMapping("info")
    public Result getShopInfo(){
        return Result.success(shopService.getById((Integer)UserThreadLocal.get().get("shopId")));
    }

    @ApiOperation("根据id更新店铺")
    @RepeatSubmit(interval = 2000, message = "接口请求过于频繁")
    @PostMapping("update")
    public Result updateShopInfo(@RequestBody Shop shop){
        return Result.success(shopService.updateById(shop));
    }
}
